/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jule.clases.treeFiles;

import java.io.File;
import java.util.Enumeration;

import javax.swing.tree.TreeNode;

public class FileNode implements TreeNode {

       public File file;

       private DirectoryNode parentNode;

       public FileNode(File file, DirectoryNode parentNode) {
               if (file == null) {
                       throw new IllegalArgumentException("File object " +
                                       "is null");
               }
               if (file.isFile()) {
                       this.file = file;
               } else {
                       throw new IllegalArgumentException(
                                       "File object is not a file. " +
                                       "It could be a directory");
               }
               this.parentNode = parentNode;
       }

       public Enumeration children() {
               return new Enumeration() {
                       public boolean hasMoreElements() {
                               return false;
                       }

                       public Object nextElement() {
                               return null;
                       }
               };
       }

       public boolean getAllowsChildren() {
               return false;
       }

       public TreeNode getChildAt(int arg0) {
               return null;
       }

       public int getChildCount() {
               return 0;
       }

       public int getIndex(TreeNode arg0) {
               return -1;
       }

       public TreeNode getParent() {
               return parentNode;
       }

       public boolean isLeaf() {
               return true;
       }

       public String toString() {
               return file.getName();
       }
}
